package com.pinda.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pinda.feign.PdOrderFeignClient;
import com.pinda.mapper.PdTaskPickupDispatchMapper;
import com.pinda.service.IPdTaskPickupDispatchService;
import com.pinda.service.IPdTransportOrderService;
import com.pinda.work.entity.PdTaskPickupDispatch;
import com.pinda.work.entity.PdTickupAndOrder;
import com.pinda.work.vo.Dispatch_Order;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 取件、派件任务信息表 服务实现类
 * </p>
 *
 * @author lc
 * @since 2023-06-14
 */
@Service
public class PdTaskPickupDispatchServiceImpl extends ServiceImpl<PdTaskPickupDispatchMapper, PdTaskPickupDispatch> implements IPdTaskPickupDispatchService {

    @Resource
    private PdTaskPickupDispatchMapper pdTaskPickupDispatchMapper;
    @Resource
    private PdOrderFeignClient pdOrderFeignClient;
    @Resource
    private IPdTransportOrderService iPdTransportOrderService;

    @Override
    public List<Dispatch_Order> findDispatchByTaskType(String courierId) {
        return pdTaskPickupDispatchMapper.findDispatchByTaskType(courierId);
    }

    @Override
    public List<Dispatch_Order> findDispatchByTaskType3(String courierId) {
        return pdTaskPickupDispatchMapper.findDispatchByTaskType3(courierId);
    }


    /**
     * 根据快递员查询待收件
     * @param courierid
     * @return
     */
    @Override
    public List<Dispatch_Order> selectreceiving(String courierid) {
        return pdTaskPickupDispatchMapper.selectreceiving(courierid);
    }

    /**
     * 收件须交件
     * @param courierid
     * @return
     */
    @Override
    public List<Dispatch_Order> selectreceiving2(String courierid) {
        return pdTaskPickupDispatchMapper.selectreceiving2(courierid);
    }

    @Override
    public List<Dispatch_Order> canceled(String courierid) {
        return pdTaskPickupDispatchMapper.canceled(courierid);
    }

    @Override
    public List<Dispatch_Order> findDispatchByCourierId(PdTaskPickupDispatch pdTaskPickupDispatch) {
        return pdTaskPickupDispatchMapper.findDispatchByCourierId(pdTaskPickupDispatch);
    }

    @Override
    public boolean updatareceivingByid4(String id, String id1,int paymentMethod) {
        /**
         * 修改状态为4
         */
        boolean b = pdTaskPickupDispatchMapper.updatareceivingByid4(id);

        if(b && paymentMethod==2){
            /**
             * 修改订单已付款
             */
            pdOrderFeignClient.UpdOrderById(id1);
            iPdTransportOrderService.UpdTransportOrder(id1);

        }
        return pdOrderFeignClient.updateStatusById9(id1);

    }
    @Override
    public void updatecourierid(PdTickupAndOrder pdTickupAndOrder) {
        pdTaskPickupDispatchMapper.updatecourierid(pdTickupAndOrder);
    }

    @Override
    public void updatecourieridone(PdTickupAndOrder pdTickupAndOrder) {
        pdTaskPickupDispatchMapper.updatecourieridone(pdTickupAndOrder);
    }

    @Override
    public void insertPickup(PdTaskPickupDispatch pdTaskPickupDispatch) {
        pdTaskPickupDispatchMapper.insert(pdTaskPickupDispatch);
    }
}
